/*
 * license-updater - Copyright (c) 2012 MSF. All rights reserved.
 * 
 * This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General
 * Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 * 
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to
 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
 */
package br.msf.commons.netbeans.util;

import java.util.regex.Pattern;

/**
 * <p>TODO
 *
 * @author Marcius da Silva da Fonseca (sf.marcius@gmail.com)
 * @version 1.0
 * @since license-updater-1.0
 */
public enum FileType {

    JAVA_SRC("java"),
    XML_SRC("xml"),
    PROPS_SRC("properties"),
    HTML_SRC("html|htm|xhtml"),
    OTHER("");
    private final String ext;

    private FileType(String ext) {
        this.ext = ext.toLowerCase();
    }

    public String getExt() {
        return this.ext;
    }

    public static FileType parse(String ext) {
        for (FileType fileType : FileType.values()) {
            if (Pattern.compile(fileType.getExt()).matcher(ext.toLowerCase()).matches()) {
                return fileType;
            }
        }
        return FileType.OTHER;
    }

    public static boolean isJava(String ext) {
        return JAVA_SRC.equals(parse(ext));
    }

    public static boolean isXML(String ext) {
        return XML_SRC.equals(parse(ext));
    }

    public static boolean isProperties(String ext) {
        return PROPS_SRC.equals(parse(ext));
    }
}
